package com.pd.backend.utils;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * 验证码随机生成
 * @Auther : 菜鸡编程
 * @Date:2023/1/11
 * @Description:
 * @VERSON:1.8
 */
public class AuthCodeUtils {
        public static String[] fuhao = {"+", "-", "*", "/"};


        public static int num = 0;

        public static String result = "";

        // 生成随机算式
        public static String random() {

            List list = new ArrayList();

            Random ran = new Random();

            int n1 = ran.nextInt(10);

            int n2 = ran.nextInt(10);

            String f = fuhao[ran.nextInt(fuhao.length)];

            StringBuilder sb = new StringBuilder(4);

            switch (f) {
                case "+":
                    num = n1 + n2;
                    break;
                case "-":
                    num = n1 - n2;
                    break;
                case "*":
                    num = n1 * n2;
                    break;
                case "/":
                    if (n2 == 0) {
                        n2 = ran.nextInt(10) + 1;
                        num = n1 / n2;
                    } else {
                        num = n1 / n2;
                    }
                    break;
            }
            sb.append(n1);
            sb.append(f);
            sb.append(n2);
            sb.append("=");

            result = num + "";
            return sb.toString();
        }


    public static void main(String[] args) {
        //测试验证码生成是否合理
        //公式
        System.out.println(random());
        //输出结果
        System.out.println(AuthCodeUtils.result);
    }

    }



